home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / p_man / cat3s / popen.z / popen
Text File  |  1998-10-20  |  6KB  |  133 lines

  1.  
  2.  
  3.  
  4. PPPPOOOOPPPPEEEENNNN((((3333SSSS))))                                                            PPPPOOOOPPPPEEEENNNN((((3333SSSS))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      popen, pclose - initiate pipe to/from a process
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssttttddddiiiioooo....hhhh>>>>
  13.  
  14.      FFFFIIIILLLLEEEE ****ppppooooppppeeeennnn ((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ccccoooommmmmmmmaaaannnndddd,,,, ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ttttyyyyppppeeee))));;;;
  15.  
  16.      iiiinnnntttt ppppcccclllloooosssseeee ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm))));;;;
  17.  
  18. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  19.      _p_o_p_e_n creates a pipe between the calling program and the command to be
  20.      executed.  The arguments to _p_o_p_e_n are pointers to null-terminated
  21.      strings.  _C_o_m_m_a_n_d consists of a shell command line.  _T_y_p_e is an I/O mode,
  22.      either rrrr for reading or wwww for writing.  The value returned is a stream
  23.      pointer such that one can write to the standard input of the command, if
  24.      the I/O mode is wwww, by writing to the file _s_t_r_e_a_m; and one can read from
  25.      the standard output of the command, if the I/O mode is rrrr, by reading from
  26.      the file _s_t_r_e_a_m.
  27.  
  28.      A stream opened by _p_o_p_e_n should be closed by _p_c_l_o_s_e, which waits for the
  29.      associated process to terminate and returns the exit status of the
  30.      command.
  31.  
  32.      Because open files are shared, a type rrrr command may be used as an input
  33.      filter and a type wwww as an output filter.
  34.  
  35. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  36.      A typical call may be:
  37.  
  38.           _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
  39.           _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
  40.  
  41.           _mmmm_aaaa_iiii_nnnn_((((_))))
  42.           _{{{{
  43.                   _cccc_hhhh_aaaa_rrrr _****_cccc_mmmm_dddd _==== _""""_////_uuuu_ssss_rrrr_////_bbbb_iiii_nnnn_////_llll_ssss _****_...._cccc_""""_;;;;
  44.                   _cccc_hhhh_aaaa_rrrr _bbbb_uuuu_ffff_[[[[_BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ_]]]]_;;;;
  45.                   _FFFF_IIII_LLLL_EEEE _****_pppp_tttt_rrrr_;;;;
  46.  
  47.                   _iiii_ffff _((((_((((_pppp_tttt_rrrr _==== _pppp_oooo_pppp_eeee_nnnn_((((_cccc_mmmm_dddd_,,,, _""""_rrrr_""""_))))_)))) _!!!!_==== _NNNN_UUUU_LLLL_LLLL_))))
  48.                           _wwww_hhhh_iiii_llll_eeee _((((_ffff_gggg_eeee_tttt_ssss_((((_bbbb_uuuu_ffff_,,,, _BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ_,,,, _pppp_tttt_rrrr_)))) _!!!!_==== _NNNN_UUUU_LLLL_LLLL_))))
  49.                                   _((((_vvvv_oooo_iiii_dddd_)))) _pppp_rrrr_iiii_nnnn_tttt_ffff_((((_""""_%%%%_ssss_""""_,,,, _bbbb_uuuu_ffff_))))_;;;;
  50.                   _rrrr_eeee_tttt_uuuu_rrrr_nnnn _0000_;;;;
  51.           _}}}}
  52.  
  53.      This will print in _s_t_d_o_u_t [see _s_t_d_i_o (3S)] all the file names in the
  54.      current directory that have a ``.c'' suffix.
  55.  
  56. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  57.      pipe(2), wait(2), fclose(3S), fopen(3S), stdio(3S), system(3S).
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PPPPOOOOPPPPEEEENNNN((((3333SSSS))))                                                            PPPPOOOOPPPPEEEENNNN((((3333SSSS))))
  71.  
  72.  
  73.  
  74. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  75.      _p_o_p_e_n returns a NULL pointer if files or processes cannot be created.
  76.  
  77.      _P_c_l_o_s_e returns -1 if _s_t_r_e_a_m is not associated with a ``_p_o_p_e_ned'' command.
  78.  
  79. WWWWAAAARRRRNNNNIIIINNNNGGGG
  80.      If the original and ``_p_o_p_e_ned'' processes concurrently read or write a
  81.      common file, neither should use buffered I/O, because the buffering gets
  82.      all mixed up.  Problems with an output filter may be forestalled by
  83.      careful buffer flushing, e.g. with _f_f_l_u_s_h [see _f_c_l_o_s_e(3S)].
  84.  
  85.      Full pathnames should be used (or reset PATH variable) and the IFS
  86.      environment variable should be set to space and tab("\_t") to avoid
  87.      possible security problems.  It should be noted that these environment
  88.      variables are inherited from the parent process.
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.